/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
void CreatNode(struct ListNode* Head, int val) {
    struct ListNode* p = (struct ListNode*)malloc(sizeof(struct ListNode));
    p->next = NULL;
    p->val = val;
    struct ListNode* sub = (struct ListNode*)malloc(sizeof(struct ListNode));
    sub = Head;
    while (sub->next != NULL) {
        sub = sub->next;
    }
    if (sub->next == NULL) {
        sub->next = p;
    }
}

int sum = 0; 
int next = 0;

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
    struct ListNode* Head = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* subHead = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* subl1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* subl2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    Head->next = NULL;
    Head->val = 0;
    subHead = Head;
    subl1 = l1;
    subl2 = l2;
    //
    next = 0;
    if(subl1->next != NULL && subl2->next != NULL){
        while(subl1->next != NULL && subl2->next != NULL){
            sum = subl1->val+subl2->val+next;
            if(sum<10){
                CreatNode(Head,sum);
                next = sum / 10;
            }
            else{
                CreatNode(Head,sum%10);
                next = sum / 10;
            }
            subl1 = subl1->next;
            subl2 = subl2->next;
        }
    }
    //最后需要额外加一次
    sum = subl1->val + subl2->val + next;
        if(sum < 10){
            CreatNode(Head,sum);
            next = sum / 10;
        }
        else{
            CreatNode(Head,sum % 10);
            next = sum / 10;
        }


    //

    int judgel1 = 0;
    if( subl1->next != NULL ){
        subl1 = subl1->next;
        while( subl1->next != NULL ){
            sum = subl1->val + next;
            if(sum < 10){
                CreatNode(Head,sum);
                next = sum / 10;
            }
            else{
                CreatNode(Head,sum % 10);
                next = sum / 10;
            }
            subl1 = subl1->next;
        }
        judgel1 = 1;
    }
    if(judgel1 == 1){
        sum = subl1->val + next;
            if(sum < 10){
                CreatNode(Head,sum);
            }
            else{
                CreatNode(Head,sum % 10);
                CreatNode(Head,sum / 10);
            }
    }
    //
    
    int judgel2 = 0;
    if( subl2->next != NULL ){
        subl2 = subl2->next;
        while( subl2->next != NULL ){
            sum = subl2->val + next;
            if(sum < 10){
                CreatNode(Head,sum);
                next = sum / 10;
            }
            else{
                CreatNode(Head,sum % 10);
                next = sum / 10;
            }
            subl2 = subl2->next;
        }
        judgel2 = 1;
    }
    if(judgel2 == 1){
        sum = subl2->val + next;
            if(sum < 10){
                CreatNode(Head,sum);
            }
            else{
                CreatNode(Head,sum % 10);
                CreatNode(Head,sum / 10);
            }
    }
    if(judgel1 == 0 && judgel2 == 0 && sum >= 10){
        CreatNode(Head,1);
    }
    return Head->next;
}